

from statistics import mode


ernie_model = QianfanChatEndpoint(
    qianfan_ak=os.getenv("xxxx"),
    qianfan_sk=os.getenv("")
)

gpt_model=ChatOpenAI(model="gpt-4o-mini", temperature=0)

model = model2.configurable_alternatives(
    ConfigurableField(id="llm"),  <-----------configurable_alternatives按照指定字段选择模型
    default_key="gpt",
    ernie=ernie_model,
    # claude=claude_model
)

prompt = ChatPromptTemplate.from_messages(
    [
        HumanMessagePromptTemplate.from_template("{query}")
    ]
)

chain = (
    {"query":RannablePassthrough()}
    | prompt
    | model
    | StroutputParse()
)

ret = chain.with_config(configurable={"llm":"gpt"}).invoke("xxxxx")  
print(ret)